﻿using AutoMapper;
using commodity.Dtos;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace commodity.Profiles
{
    public class CatProflie:Profile
    {
        public CatProflie() 
        {
            CreateMap<FirstsCommdityMenuDto, CatDto>()
                    .ForMember(
                desp => desp.Cat_Name,
                opt => opt.MapFrom(src => src.Name)
                ).ForMember(
                desp => desp.Cat_Id,
                opt => opt.MapFrom(src => src.Id)
                ).ForMember(
                desp => desp.Cat_Level,
                opt => opt.MapFrom(src => 0)
                ).ForMember(
                desp => desp.Children,
                opt => opt.MapFrom(src => src.SecondCommodityMenus)
                );
            CreateMap<SecondCommdityMenuDto, CatDto>()
                    .ForMember(
                desp => desp.Cat_Name,
                opt => opt.MapFrom(src => src.Name)
                ).ForMember(
                desp => desp.Cat_Id,
                opt => opt.MapFrom(src => src.Id)
                ).ForMember(
                desp => desp.Cat_Level,
                opt => opt.MapFrom(src => 1)
                ).ForMember(
                desp => desp.Children,
                opt => opt.MapFrom(src => src.SecondCommodityMenuCommodities)
                ).ForMember(
                desp=>desp.Cat_pid,
                opt=>opt.MapFrom(src=>src.FirstsCommodityMenuId)
                );
            CreateMap<SecondCommodityMenuCommodityDto, CatDto>()
                    .ForMember(
                desp => desp.Cat_Name,
                opt => opt.MapFrom(src => src.Commodity.CommodityName)
                ).ForMember(
                desp => desp.Cat_Id,
                opt => opt.MapFrom(src => src.Commodity.id)
                ).ForMember(
                desp => desp.Cat_Level,
                opt => opt.MapFrom(src => 2)
                ).ForMember(
                desp => desp.Children,
                opt => opt.MapFrom(src => new List<string>())
                ).ForMember(
                desp => desp.Cat_pid,
                opt => opt.MapFrom(src => src.SecondCommodityMenuId)
                );
        }
    }
}
